package swordoffer.offer30;

import java.util.ArrayDeque;
import java.util.Deque;

public class OnlyStack {
    class MinStack {
        private Deque<int[]> stack;
        /** initialize your data structure here. */
        public MinStack() {
            this.stack = new ArrayDeque<>();
        }

        public void push(int x) {
            if (stack.isEmpty()) {
                stack.push(new int[] {x, x});
            } else {
                stack.push(new int[] {x, Math.min(stack.peek()[1], x)});
            }
        }

        public void pop() {
            if (!stack.isEmpty()) {
                stack.pop();
            }
        }

        public int top() {
            if (!stack.isEmpty()) {
                return stack.peek()[0];
            }
            return -1;
        }

        public int min() {
            if (!stack.isEmpty()) {
                return stack.peek()[1];
            }
            return -1;
        }
    }
}
